package com.hsj.springai.controller;

import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/function")
public class FunctionCallController {

    @Autowired
    private OpenAiChatModel openAiChatModel;

    @GetMapping("/city")
    public String weather(){
        UserMessage userMessage = new UserMessage("What's the weather like in 北京, 上海, and 南京?,用中文回答啊");
        var promptOptions = OpenAiChatOptions.builder()
                .withFunction("mockWeather")
                .withModel("gpt-4-0314")
                .build();

        ChatResponse response = openAiChatModel.call(new Prompt(List.of(userMessage), promptOptions));
        String content = response.getResult().getOutput().getContent();
        return content;
    }
}
